package com.xiaoxi.visitormode;

import com.xiaoxi.visitormode.composite.Directory;
import com.xiaoxi.visitormode.composite.File;
import com.xiaoxi.visitormode.composite.FileNotAddException;
import com.xiaoxi.visitormode.visitor.FileFindVisitor;
import com.xiaoxi.visitormode.visitor.ListVisitor;
import com.xiaoxi.visitormode.visitor.Visitor;

import java.util.Iterator;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.visitormode
 * @ClassName Main
 * @Description TODO
 * @Date 2023/3/16 15:39
 * @Version 1.0
 */
public class Main {
    public static void main(String[] args) {
        try {
            Directory root = new Directory("root");
            File txt1 = new File("1.txt", 200);
            File txt2 = new File("2.txt", 200);
            File txt3 = new File("3.txt", 200);

            Directory tmp = new Directory("tmp");
            File html1 = new File("1.html", 200);
            File html2 = new File("2.html", 200);
            File html3 = new File("3.html", 200);
            tmp.add(html1);
            tmp.add(html2);
            tmp.add(html3);

            root.add(tmp);
            root.add(txt1);
            root.add(txt2);
            root.add(txt3);

            root.printList("");

            System.out.println("-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0");

            System.out.println(html1.pwd());
            System.out.println(tmp.pwd());

            System.out.println("-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0");

            Visitor visitor = new ListVisitor();
            visitor.visit(tmp);
            visitor.visit(html1);

            FileFindVisitor visitor1 = new FileFindVisitor(".html");
            visitor1.visit(root);

            Iterator iterator = visitor1.createIterator();
            while(iterator.hasNext()) {
                System.out.println(iterator.next());
            }

        } catch (FileNotAddException e) {
            System.out.println("出错：" + e.getMessage());
        }



    }
}
